import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sainbainu/common/models/response/version_list_response.dart';
import 'package:sainbainu/common/values/colors.dart';

import '../index.dart';

typedef UpdateTap = void Function(VersionItemResponse item);

class VersionDetail extends GetView<VersionController> {
  final VersionItemResponse item;
  final UpdateTap? onUpdateTap;

  const VersionDetail({
    Key? key,
    required this.item,
    this.onUpdateTap,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        automaticallyImplyLeading: false,
        title: const Text('版本详情'),
        backgroundColor: AppColors.page,
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.symmetric(horizontal: 15),
        child: Align(
          alignment: Alignment.topCenter,
          child: Column(
            children: [
              const SizedBox(height: 50),
              Image.asset('assets/images/logo.png', width: 150),
              const SizedBox(height: 10),
              Text(
                'Version ${item.versionName}',
                style: const TextStyle(fontSize: 20, color: AppColors.active),
              ),
              const SizedBox(height: 5),
              Text(
                '发布于 ${item.createTime}',
                style: const TextStyle(fontSize: 13, color: AppColors.unactive),
              ),
              const SizedBox(height: 30),
              const SizedBox(
                width: double.infinity,
                child: Text(
                  '更新内容',
                  style: TextStyle(
                    fontSize: 16,
                    color: AppColors.active,
                  ),
                ),
              ),
              const SizedBox(height: 5),
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: item.updateContentList!
                    .map(
                      (t) => SizedBox(
                        width: double.infinity,
                        child: Text(
                          t,
                          style: const TextStyle(
                            fontSize: 14,
                            color: AppColors.active,
                          ),
                        ),
                      ),
                    )
                    .toList(),
              ),
            ],
          ),
        ),
      ),
      bottomNavigationBar: item.canUpdate
          ? BottomAppBar(
              color: AppColors.page,
              padding: const EdgeInsets.symmetric(horizontal: 15),
              height: kBottomNavigationBarHeight,
              child: Row(
                children: [
                  Expanded(
                    child: ElevatedButton(
                      style: ElevatedButton.styleFrom(
                        backgroundColor: AppColors.danger,
                        foregroundColor: Colors.white,
                      ),
                      onPressed: () {
                        if (onUpdateTap != null) {
                          onUpdateTap!(item);
                        }
                      },
                      child: const Text('立即更新'),
                    ),
                  ),
                ],
              ),
            )
          : null,
    );
  }
}
